import Vue from 'vue'
import Vuex from 'vuex'
import { GetNavigationMenus } from '@/api/Login'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    menuData: {
      Result: {
        TopMenus: [],
        LeftMenus: []
      }
    }
  },
  mutations: {
    SET_MENU_DATA(state, menuData) {
      state.menuData = menuData
    }
  },
  actions: {
    async fetchMenuData({ commit }, query) {
      try {
        const response = await GetNavigationMenus(query)
        if (response.Code === 200) {
          commit('SET_MENU_DATA', response)
        }
      } catch (error) {
        console.error('获取导航菜单失败:', error)
      }
    }
  }
})
